<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no,email=no,adress=no"/>
<title>先花花</title>
<link rel="stylesheet" type="text/css" href="css/setting.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="script/jquery.js"></script>
<script type="text/javascript" src="script/common.js"></script>
<script type="text/javascript" src="script/jquery.md5.js"></script>
<script type="text/javascript" src="script/jquery.cookie.js"></script>
<script src="script/setting.js"></script>
<script type="text/javascript">
    $(function(){
      get_tel();
      $("#zphone").click(function(){
        get_mobile_code();
      });
      $("#btn").click(function(){
        if(checkMobilenumber()&&doubles()&&isPoneAvailable()){
          get_verify();
        }
      });
      $("#tel1").blur(function(){
        isPoneAvailable(tel1);
      })
    });
    function isPoneAvailable() {  
          var myreg=/^[1][3,4,5,7,8][0-9]{9}$/; 
          var tel1 = parseInt($("#tel1").val()); 
          if (!myreg.test(tel1)) {  
              $("#mobileNumberErrorDiv").empty();
              $("#mobileNumberErrorDiv").append("手机格式不正确");
              return false;
          } else {  
            $("#mobileNumberErrorDiv").empty();
              return true;  
          }  
      }  
    function doubles(){
      var old = parseInt($("#tel").val());
      var newTel = parseInt($("#tel1").val());
      if(old == newTel){
        alert('不能与原手机号相同');
        return false;
      }
      return true;
    }
    function checkMobilenumber()
    {
      var tel1 = parseInt($("#tel1").val());
      var tel2 = parseInt($("#tel2").val());
      if(tel1!=tel2)
      {
        $("#mobileNumberErrorDiv").empty();
        $("#mobileNumberErrorDiv").append("两次手机号不一样");
        return false;
      }
      else
      {
        $("#mobileNumberErrorDiv").empty();
        return true;
      }
    }
    function get_tel(){
      $.ajax({
          url:commonUrl+"/Userinfo/index",
          data:{appid:appid,appkey:appkey,uid:uid},
          type:"get",
          dataType:"jsonp",
          jsonp:"callback",
          success:function(result){
            $("#tel").val(result.data.account);
            $("#tel3").html(result.data.tel1);
          },
          error:function(){
            alert(1)
          }
      });
    }
    function updateTel(){
      var tel = parseInt($("#tel1").val());
      $.ajax({
          url:commonUrl+"/Userinfo/updateTel",
          data:{appid:appid,appkey:appkey,tel:tel,uid:uid},
          type:"get",
          dataType:"jsonp",
          jsonp:"callback",
          success:function(result){
            alert(result.msg);
            window.location.href="user.html";
          }
      });
    }
    function get_verify(){
      var code = $("#code").val();
      $.ajax({
           url:commonUrl+"/sendmessage/verify",
           data:{appid:appid,appkey:appkey,code:code},
           type:"get",
           dataType:"JSONP",
           jsonp:"callback",
           success:function(result){
            if(result.status == 200){
              updateTel();
            }else{
              alert(result.msg);
            }
           }
      });
    }
    function get_mobile_code(){
      var tel = $("#tel").val();
      if(tel ==''){
        return false;
      }
      $.ajax({
          url:commonUrl+"/sendmessage/index",
          data:{appid:appid,appkey:appkey,tel:tel},
          type:"get",
          dataType:"JSONP",
          jsonp:"callback",
          success:function(result){
            if(result.SubmitResult.code == 2){
              RemainTime();
            }else{
              alert(result.SubmitResult.msg);
            }
          }
      });
    }
      var iTime = 59;
      var Account;
      function RemainTime(){
        document.getElementById('zphone').disabled = true;
        var iSecond,sSecond="",sTime="";
        if (iTime >= 0){
          iSecond = parseInt(iTime%60);
          iMinute = parseInt(iTime/60)
          if (iSecond >= 0){
            if(iMinute>0){
              sSecond = iMinute + "分" + iSecond + "秒";
            }else{
              sSecond = iSecond + "秒";
            }
          }
          sTime=sSecond;
          if(iTime==0){
            clearTimeout(Account);
            sTime='获取手机验证码';
            iTime = 59;
            document.getElementById('zphone').disabled = false;
          }else{
            Account = setTimeout("RemainTime()",1000);
            iTime=iTime-1;
          }
        }else{
          sTime='没有倒计时';
        }
        document.getElementById('zphone').value = sTime;
    } 
</script>
</head>
<body>
<!-- 页面头部 -->
<section>
<div class="navigation-bar"> <a href="javascript:history.back(-1)" class="z-01"></a> <span>修改手机号码</span> <a href="index.html" class="z-02"></a> </div>
</section>
<!-- 中间内容 -->
<div class="m-wrapper">
  <div class="wrapper   ">
    <div class="login-password" id="set-pay-pass">
      <div class="container-fluid">
        <input type="hidden" id="tel">
        <p class="pay-p">请输入手机号 <span id="tel3">150****0139</span> 收到的短信验证码</p>
        <form class="form-inline" onsubmit="return false;" novalidate="novalidate">
          <input type="text" id="code" class="input-small phone input-lg" tabindex="1" placeholder="请输入短信验证码">
          <input type="button" value="获取验证码" id="zphone" class="inline-btn pull-right waves-button form-control login-button input-lg  default waves-effect sms-button waves-effect" tabindex="2" ></input>
        </form>
        <form class="login-form1" id="login-form" onsubmit="return false;" novalidate="novalidate">
          <div class="form-group">
            <input type="text" class="form-control input-lg set-new-pay" id="tel1" name="password" tabindex="2" placeholder="请输入新手机号码"><label id="mobileNumberErrorDiv"></label>
          </div>
          <div class="form-group">
            <input type="text" class="form-control input-lg new-pay-pass" name="password" id="tel2" tabindex="3" placeholder="请确认新手机号码">
          </div>
          <div class="form-group">
            <button type="button" name="btn" class="waves-button form-control login-button input-lg  default waves-effect waves-effect" tabindex="5" id="btn">确定</button>
          </div>
          
        </form>
        <div>
          <p class="text-center ui-fs-12 text-nowrap">若您无法通过该方式重设手机号码，请联系客服电话</p>
          <p class="text-center ui-fs-12 text-nowrap"><span>400-090-1268</span></p>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 页面底部 -->
<nav class="footer border_t" id="footer"> 
  <a href="index.html" class="" id="jx"><span></span>首页</a>
   <a href="list.html" id="lc" class=""><span></span>理财</a> 
  <a href="borrow_money.html" id="jk" class=""><span></span>借款</a>
   <a href="user.html" id="cf" class="nav_on"><span></span>我的账户</a> </nav>
</body>
</html>
